migrate from QRegExp to QRegularExpression. (#729)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sun, 10 Oct 2021 21:54:44 +0000 (15:54 -0600)
committerGitHub <noreply@github.com>
Sun, 10 Oct 2021 21:54:44 +0000 (15:54 -0600)
csv_util.cc
csv_util.h

index 70bad0d66ef0bc11fb08bf956fad28231596d307..33128e756d01588cc47e2b6ad67a09ceea58bed3 100644 (file)
 
  */
 
-#include <cmath>           // for fabs
-#include <cstdio>          // for size_t
-#include <cstdlib>         // for atof, strtod
-#include <cctype>          // for isspace
-#include <cstring>         // for strlen, strchr, strncmp, strcmp, memmove, strcpy, strcspn, strncpy
-
-#include <QRegExp>         // for QRegExp
-#include <QString>         // for QString
+#include <assert.h>            // for assert
+#include <cctype>              // for isspace
+#include <cmath>               // for fabs
+#include <cstdio>              // for size_t
+#include <cstdlib>             // for atof, strtod
+#include <cstring>             // for strlen, strchr, strncmp, strcmp, memmove, strcpy, strcspn, strncpy
+
+#include <QChar>               // for QChar
+#include <QDebug>              // for QDebug
+#include <QRegularExpression>  // for QRegularExpression
+#include <QString>             // for QString, operator+
+#include <QStringRef>          // for QStringRef
 
 #include "defs.h"
 #include "csv_util.h"
-#include "src/core/logging.h"
+#include "src/core/logging.h"  // for Warning
+
 
 #define MYNAME "CSV_UTIL"
 
@@ -48,8 +53,12 @@ QString
 csv_stringclean(const QString& source, const QString& to_nuke)
 {
   QString r = source;
-  QString regex = QString("[%1]").arg(to_nuke);
-  return r.remove(QRegExp(regex));
+  // avoid problematic regular rexpressions, e.g. xmapwpt generated [:\n:],
+  // or one can imagine [0-9] when we meant the characters, '0', '-', and '9',
+  // or one can imagine [^a] when we meant the characters '^' and 'a'.
+  QRegularExpression regex = QRegularExpression(QString("[%1]").arg(QRegularExpression::escape(to_nuke)));
+  assert(regex.isValid());
+  return r.remove(regex);
 }
 
 // csv_stringtrim() - trim whitespace and leading and trailing
index 3980db4ce1e86197cbb2fc1ad7de28cb8e522d19..4ea9fa0be85d72af2a4e0c5c1b3eb84f3baa22e6 100644 (file)
 #ifndef CSV_UTIL_H_INCLUDED_
 #define CSV_UTIL_H_INCLUDED_
 
-#include <QString>             // for QString
+#include <QString>      // for QString
+#include <QStringList>  // for QStringList
 
 #include "defs.h"
 
+
 /* function prototypes */
 
 QString